package com.my.demoo2.controller;

import com.my.demoo2.config.RedisConfig;
import com.my.demoo2.config.RedisUtil;
import com.my.demoo2.entity.UserInfo;
import com.my.demoo2.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController

public class HomeController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private RedisUtil redisUtil;
    @ApiOperation(value = "获取所有用户",notes = "查询用户表的用户集合",httpMethod = "GET",protocols = "HTTP",response = List.class,produces = "appliction.json")
    @GetMapping("/show")
    public List<UserInfo> show(){
        return userInfoService.getUser();
    }
    @PostMapping("/update")
    @ApiOperation(value = "修改用户信息",notes = "修改用户信息",httpMethod = "POST",protocols = "HTTP",response = List.class,produces = "appliction.json")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body",value = "用户对象",name = "userInfo",required = true)
    })
    public boolean update(@RequestBody UserInfo userInfo){
        boolean flag = userInfoService.update(userInfo);
        return  flag;
    }
    @ApiOperation(value = "测试redis存值",notes = "测试redis存值",httpMethod = "GET",protocols = "HTTP",response = List.class,produces = "appliction.json")
    @GetMapping("/set")
    public boolean set(){
        redisUtil.set("name","张三");
        redisUtil.set("age",20);
        return true;
    }
    @ApiOperation(value = "测试redis存值",notes = "测试redis存值",httpMethod = "GET",protocols = "HTTP",response = List.class,produces = "appliction.json")
    @GetMapping("/get")
    public String get(){
        Object name = redisUtil.get("name");
        return name.toString();
    }
}
